<template>
  <div class="dialog">
    <el-dialog :title="title" :visible.sync="visible" :close-on-click-modal="false" width="70%" top="10vh" append-to-body>
      <el-form ref="tblMain" :model="tblMain" labelPosition="right" inline="" label-suffix=":" label-width="80px">
        <el-form-item label="名称">
          <el-input v-model="tblMain.param.name" size="small" placeholder=""></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <el-button type="primary" size="small" @click="initTableData()">查询</el-button>
          <el-button size="small" @click="dataReset()">清空</el-button>
        </el-form-item>
      </el-form>
      <el-table ref="tblMain" :data="tblMain.items" v-loading.body="tblMain.loading" border stripe>
        <el-table-column type="index" width="80" label="序号" align="center"></el-table-column>
        <el-table-column prop="itemId" v-if="false"></el-table-column>
        <el-table-column prop="itemName" label="财务科目名称" align="center"></el-table-column>
        <el-table-column prop="itemNumber" label="数量" align="center"></el-table-column>
        <el-table-column prop="itemPrice" label="价格" align="center"></el-table-column>
        <el-table-column prop="itemTotalprice" label="总价" align="center"></el-table-column>
        <el-table-column prop="itemUnit" label="计量单位" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="handleSelect(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="margin-top: 10px" :current-page.sync="tblMain.currentPage" :page-size="tblMain.pageSize"
        :total="tblMain.total" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange"
        @current-change="handleCurrentChange"></el-pagination>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeNetWorker()">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { themeModelDetailList } from "@/api/theme";
import tool from "@/tool";
export default {
  name: "SubjectListDialog",
  data() {
    return {
      title: "财务科目选择",
      visible: false,
      createForm: {},
      tblMain: tool.genTableData({
        param: {
          name: "",
        },
        items: [],
      }),
    };
  },
  created() { },
  mounted() { },
  methods: {
    add() {
      this.visible = true;
      this.initTableData();
    },
    handleSelect(row) {
      this.$emit("ok", row);
      this.closeNetWorker();
    },
    closeNetWorker() {
      this.tblMain.items = [];
      this.visible = false;
    },
    handleSizeChange(val) {
      this.tblMain.pageSize = val;
      this.initTableData();
    },
    handleCurrentChange(val) {
      this.tblMain.currentPage = val;
      this.initTableData();
    },
    dataReset() {
      this.tblMain.currentPage = 1;
      this.tblMain.pageSize = 10;
      this.tblMain.param.name = "";
      this.initTableData();
    },
    initTableData() {
      let me = this;
      let param = {
        name: me.tblMain.param.name,
        page: me.tblMain.currentPage,
        size: me.tblMain.pageSize,
      };
      me.tblMain.loading = true;
      themeModelDetailList(param).then((res) => {
        me.tblMain.loading = false;
        let data = res.data;
        if (data && data.code == 0) {
          me.tblMain.items = data.data.records;
          me.tblMain.total = data.data.total;
        }
      });
    },
  },
};
</script>

<style scoped></style>
